enum HttpMethod {
  GET,
  POST,
  UploadPost,
}

/// 基础请求
abstract class HiBaseRequest {
  var topPath;
  var pathParams;
  var useHttps = true;
  String authority() {
    return '192.168.18.23:8888';
  }

  HttpMethod httpMethod();
  String path();
  String url() {
    Uri uri;
    var pathStr = '';
    if (topPath != null) {
      pathStr = topPath;
    }
    if(path().startsWith('/')) {
      pathStr += path();
    } else {
      pathStr += '/${path()}';
    }
    // 拼接path参数
    if (pathParams != null) {
      pathStr += '/$pathParams';
    }
    // http和https的切换
    if (useHttps) {
      uri = Uri.https(authority(), pathStr);
    } else {
      uri = Uri.http(authority(), pathStr);
    }

    return uri.toString();
  }

  bool needLogin();

  Map<String, dynamic> params = {};
  // 添加参数
  HiBaseRequest add(String k, Object v) {
    params[k] = v;
    return this;
  }

  Map<String, dynamic> headers = {};
  // 添加header
  HiBaseRequest addHeaders(String k, Object v) {
    headers[k] = v.toString();
    return this;
  }
}
